<template>
  <el-menu
    class="categories"
    default-active="0"
    @select="handleSelect"
    active-text-color="red">
    <el-menu-item index="0">
      <i class="el-icon-menu"></i>
      <span slot="title">全部</span>
    </el-menu-item>
    <el-menu-item :index="item.id.toString()" v-for="item in categorylists" :key="item.id">
      <i class="el-icon-menu"></i>
      <span slot="title">{{item.name}}</span>
    </el-menu-item>
  </el-menu>
</template>

<script>
    export default {
      name: 'SideMenu',
      data () {
        return {
          cid: '',
          categorylists: []
        }
      },
      mounted(){
        this.Categorylist()
      },
      methods: {
        Categorylist() {
          this.$axios.get('/Category/list').then(resp =>{
            if(resp.data.code === 200){
              this.categorylists=resp.data.result
            }else{
              this.categorylists=resp.data.result
            }
          }).catch(fail =>{
            console.error(fail)
          })
        },
        handleSelect (key, keyPath) {
          this.cid = key
          this.$emit('indexSelect')
        }
      }
    }
</script>

<style scoped>
  .categories {
    position: fixed;
    margin-left: 50%;
    left: -600px;
    top: 100px;
    width: 150px;
  }
</style>
